// ModelLayerActiveX.cpp : Implementation of CModelLayerActiveXApp and DLL registration.

#include "stdafx.h"
#include "ModelLayerActiveX.h"
//#include "atlimage.h"
#include <ModelLayer.h>
// class CImage;
// #include "system.h"
// #include "BakFileManager.h"
// #include "ModelLayerDoc.h"
// #include "ChildFrm.h"
// #include "ModelLayerView.h"
// #include "..\ModelLayer\resource.h"
// 
// #include "BCGCBProInc.h"
// #include "RectangleObj.h"
// #include "DialogView.h"
// #include "MainFrm.h"
//using namespace ATL;



#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//extern CModelLayerApp theApp;

//CModelLayerActiveXApp theActiveXApp;

const GUID CDECL _tlid = { 0x73E80935, 0xAAEE, 0x45C9, { 0x91, 0xB4, 0xA6, 0xEB, 0x71, 0x30, 0x15, 0x3D } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;
/*
BEGIN_MESSAGE_MAP(CModelLayerActiveXApp, COleControlModule)
	ON_COMMAND(ID_FILE_OPEN, &CModelLayerActiveXApp::OnFileOpen)
	ON_COMMAND(ID_IDS_IMPORT, &CModelLayerActiveXApp::OnIdsImport)
	ON_COMMAND(ID_APP_ABOUT, &CModelLayerActiveXApp::OnAppAbout)
	// Standard file based document commands
	//	ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, &CModelLayerActiveXApp::OnFilePrintSetup)

	ON_COMMAND(IDC_LICENSE, &CModelLayerActiveXApp::OnApplylicense)
	ON_UPDATE_COMMAND_UI(IDC_LICENSE, &CModelLayerActiveXApp::OnUpdateApplylicense)
	ON_COMMAND(ID_FILE_NEW, &CModelLayerActiveXApp::OnFileNew)
	ON_UPDATE_COMMAND_UI(ID_FILE_NEW, &CModelLayerActiveXApp::OnUpdateFileNew)
	ON_COMMAND(ID_FILE_CLOSE,&CModelLayerActiveXApp::OnFileClose)
	ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE,&CModelLayerActiveXApp::OnUpdateFileClose)

END_MESSAGE_MAP()

// CModelLayerActiveXApp::InitInstance - DLL initialization

BOOL CModelLayerActiveXApp::InitInstance()
{
	BOOL bInit = COleControlModule::InitInstance();


	//SetRegistryKey(_T("Tongyuan"));
	if (bInit)
	{
		

		theApp.ModelLayerActiveXInit();
	}


	return bInit;
}



// CModelLayerActiveXApp::ExitInstance - DLL termination

int CModelLayerActiveXApp::ExitInstance()
{
	// TODO: Add your own module termination code here.

	return COleControlModule::ExitInstance();
}

BOOL CModelLayerActiveXApp::CreateFrameWnd(CWnd* pWnd)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState()); 

	HINSTANCE hDllInstance = GetModuleHandle(L"ModelLayer_d.dll");
	HINSTANCE hOcxInstance = AfxGetResourceHandle();
	AfxSetResourceHandle(hDllInstance);

	m_pMDIDocTemplate = new CMultiDocTemplate(IDR_TestLayerDisplaTYPE,
		RUNTIME_CLASS(CModelLayerDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CModelLayerView));
	if (!m_pMDIDocTemplate)
		return FALSE;
	
	AddDocTemplate(m_pMDIDocTemplate);

	CMainFrame* pMainFrame = new CMainFrame;
	if(!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPED|WS_CHILD, pWnd))
	{
		delete pMainFrame;
		return FALSE;
	}

	m_pMainWnd = pMainFrame;
	CWnd *pMainWnd = AfxGetMainWnd();
	CCommandLineInfo cmdInfo; 
	ParseCommandLine(cmdInfo); 
	cmdInfo.m_nShellCommand =CCommandLineInfo::FileNothing; 
	// Dispatch commands specified on the command line 
	if (!ProcessShellCommand(cmdInfo)) 
	{ 
		return FALSE; 
	} 

	pMainFrame->ShowWindow(SW_SHOWNORMAL);
	pMainFrame->UpdateWindow();
	
	//AfxSetResourceHandle(hOcxInstance);
	return TRUE;
}

// DllRegisterServer - Adds entries to the system registry

void CModelLayerActiveXApp::OnFileOpen()
{
	theApp.OnFileOpen();
}

void CModelLayerActiveXApp::OnIdsImport()
{
	theApp.OnIdsImport();

}

void CModelLayerActiveXApp::OnFileNew()
{
	theApp.OnFileNew();
}


void CModelLayerActiveXApp::OnAppAbout()
{
	theApp.OnAppAbout();
}

void CModelLayerActiveXApp::OnApplylicense()
{
	theApp.OnApplylicense();
}

void CModelLayerActiveXApp::OnUpdateApplylicense(CCmdUI *pCmdUI)
{
	theApp.OnUpdateApplylicense(pCmdUI);
}

void CModelLayerActiveXApp::OnUpdateFileNew(CCmdUI *pCmdUI)
{
	theApp.OnUpdateFileNew(pCmdUI);
}

void CModelLayerActiveXApp::OnFileClose()
{
	theApp.OnFileClose();
}

void CModelLayerActiveXApp::OnUpdateFileClose(CCmdUI *pCmdUI)
{
	theApp.OnUpdateFileClose(pCmdUI);
}
*/

STDAPI DllRegisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}



// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}


